/*     */ package com.zimbra.cs.account.ldap.upgrade;
/*     */ 
/*     */ import com.zimbra.common.account.ZAttrProvisioning.MtaTlsSecurityLevel;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.AttributeClass;
/*     */ import com.zimbra.cs.account.Config;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import com.zimbra.cs.ldap.LdapClient;
/*     */ import com.zimbra.cs.ldap.LdapServerType;
/*     */ import com.zimbra.cs.ldap.LdapUsage;
/*     */ import com.zimbra.cs.ldap.ZLdapContext;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class BUG_33814
/*     */   extends UpgradeOp
/*     */ {
/*  38 */   private static final String TLSLEVEL_ENCRYPT = ZAttrProvisioning.MtaTlsSecurityLevel.may.toString();
/*  39 */   private static final String TLSLEVEL_MAY = ZAttrProvisioning.MtaTlsSecurityLevel.may.toString();
/*  40 */   private static final String TLSLEVEL_NONE = ZAttrProvisioning.MtaTlsSecurityLevel.none.toString();
/*     */   
/*     */   void doUpgrade() throws ServiceException
/*     */   {
/*  44 */     ZLdapContext zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
/*     */     try {
/*  46 */       doGlobalConfig(zlc);
/*  47 */       doAllServers(zlc);
/*     */     } finally {
/*  49 */       LdapClient.closeContext(zlc);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private void doMtaTlsSecurityLevelOnGlobalConfig(Entry entry, Map<String, Object> attrValues)
/*     */   {
/*  62 */     String zimbraMtaAuthEnabled = entry.getAttr("zimbraMtaAuthEnabled", false);
/*  63 */     String zimbraMtaTlsAuthOnly = entry.getAttr("zimbraMtaTlsAuthOnly", false);
/*     */     
/*  65 */     String value = null;
/*     */     
/*  67 */     if ("TRUE".equals(zimbraMtaAuthEnabled)) {
/*  68 */       if ("TRUE".equals(zimbraMtaTlsAuthOnly)) {
/*  69 */         value = TLSLEVEL_ENCRYPT;
/*     */       } else
/*  71 */         value = TLSLEVEL_MAY;
/*     */     } else {
/*  73 */       value = TLSLEVEL_NONE;
/*     */     }
/*  75 */     attrValues.put("zimbraMtaTlsSecurityLevel", value);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private void doMtaTlsSecurityLevelOnServer(Entry entry, Map<String, Object> attrValues)
/*     */   {
/*  89 */     String zimbraMtaAuthEnabledOnServer = entry.getAttr("zimbraMtaAuthEnabled", false);
/*  90 */     String zimbraMtaTlsAuthOnlyOnServer = entry.getAttr("zimbraMtaTlsAuthOnly", false);
/*     */     
/*     */ 
/*  93 */     String zimbraMtaAuthEnabled = entry.getAttr("zimbraMtaAuthEnabled");
/*  94 */     String zimbraMtaTlsAuthOnly = entry.getAttr("zimbraMtaTlsAuthOnly");
/*     */     
/*  96 */     String value = null;
/*     */     
/*  98 */     if ("TRUE".equals(zimbraMtaAuthEnabledOnServer)) {
/*  99 */       if ("TRUE".equals(zimbraMtaTlsAuthOnly)) {
/* 100 */         value = TLSLEVEL_ENCRYPT;
/*     */       } else {
/* 102 */         value = TLSLEVEL_MAY;
/*     */       }
/* 104 */     } else if ("FALSE".equals(zimbraMtaAuthEnabledOnServer)) {
/* 105 */       value = TLSLEVEL_NONE;
/*     */ 
/*     */ 
/*     */ 
/*     */     }
/* 110 */     else if ("TRUE".equals(zimbraMtaAuthEnabled)) {
/* 111 */       if ("TRUE".equals(zimbraMtaTlsAuthOnlyOnServer)) {
/* 112 */         value = TLSLEVEL_ENCRYPT;
/* 113 */       } else if ("FALSE".equals(zimbraMtaTlsAuthOnlyOnServer)) {
/* 114 */         value = TLSLEVEL_MAY;
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 126 */     if (value != null) {
/* 127 */       attrValues.put("zimbraMtaTlsSecurityLevel", value);
/*     */     }
/*     */   }
/*     */   
/*     */   private void doEntry(ZLdapContext zlc, Entry entry, String entryName, AttributeClass klass) throws ServiceException {
/* 132 */     this.printer.println();
/* 133 */     this.printer.println("------------------------------");
/* 134 */     this.printer.println("Checking " + entryName + ": ");
/*     */     
/* 136 */     StringBuilder msg = new StringBuilder();
/*     */     try {
/* 138 */       Map<String, Object> attrValues = new HashMap();
/*     */       
/*     */ 
/*     */ 
/* 142 */       String zimbraMtaAuthEnabled = entry.getAttr("zimbraMtaAuthEnabled", false);
/* 143 */       String zimbraMtaTlsAuthOnly = entry.getAttr("zimbraMtaTlsAuthOnly", false);
/*     */       
/* 145 */       this.printer.println("zimbraMtaAuthEnabled: " + zimbraMtaAuthEnabled);
/* 146 */       this.printer.println("zimbraMtaTlsAuthOnly: " + zimbraMtaTlsAuthOnly);
/* 147 */       this.printer.println();
/*     */       
/*     */ 
/* 150 */       String zimbraMtaTlsSecurityLevel = entry.getAttr("zimbraMtaTlsSecurityLevel", false);
/* 151 */       String zimbraMtaSaslAuthEnable = entry.getAttr("zimbraMtaSaslAuthEnable", false);
/*     */       
/*     */ 
/*     */ 
/* 155 */       if (zimbraMtaTlsSecurityLevel == null) {
/* 156 */         if ((entry instanceof Server)) {
/* 157 */           doMtaTlsSecurityLevelOnServer(entry, attrValues);
/*     */         } else
/* 159 */           doMtaTlsSecurityLevelOnGlobalConfig(entry, attrValues);
/*     */       } else {
/* 161 */         this.printer.println("Not updating zimbraMtaTlsSecurityLevel because there is already a value: " + zimbraMtaTlsSecurityLevel);
/*     */       }
/*     */       
/*     */ 
/*     */ 
/* 166 */       if (zimbraMtaSaslAuthEnable == null) {
/* 167 */         if (zimbraMtaAuthEnabled != null) {
/* 168 */           attrValues.put("zimbraMtaSaslAuthEnable", zimbraMtaAuthEnabled);
/*     */         }
/*     */       } else {
/* 171 */         this.printer.println("Not updating zimbraMtaSaslAuthEnable because there is already a value: " + zimbraMtaSaslAuthEnable);
/*     */       }
/*     */       
/* 174 */       if (!attrValues.isEmpty()) {
/* 175 */         boolean first = true;
/* 176 */         for (Map.Entry<String, Object> attr : attrValues.entrySet()) {
/* 177 */           if (!first)
/* 178 */             msg.append(", ");
/* 179 */           msg.append((String)attr.getKey() + "=>" + (String)attr.getValue());
/* 180 */           first = false;
/*     */         }
/*     */         
/* 183 */         this.printer.println("Updating " + entryName + ": " + msg.toString());
/* 184 */         modifyAttrs(zlc, entry, attrValues);
/*     */       }
/*     */     }
/*     */     catch (ServiceException e) {
/* 188 */       this.printer.println("Caught ServiceException while modifying " + entryName + ": " + msg.toString());
/* 189 */       this.printer.printStackTrace(e);
/*     */     }
/*     */   }
/*     */   
/*     */   private void doGlobalConfig(ZLdapContext zlc) throws ServiceException {
/* 194 */     Config config = this.prov.getConfig();
/* 195 */     doEntry(zlc, config, "global config", AttributeClass.globalConfig);
/*     */   }
/*     */   
/*     */   private void doAllServers(ZLdapContext zlc) throws ServiceException {
/* 199 */     List<Server> servers = this.prov.getAllServers();
/*     */     
/* 201 */     for (Server server : servers) {
/* 202 */       doEntry(zlc, server, "server " + server.getName(), AttributeClass.server);
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/upgrade/BUG_33814.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */